﻿Public Class clsPhieuMuon
    ''' <summary>
    ''' Trả về true nếu mã phiếu hợp lệ (chưa có)
    ''' </summary>
    ''' <param name="MaPhieu"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function KiemTraMaPhieu(ByVal MaPhieu As String) As Boolean
        Return (db.QueryTable("Select MaPM from PhieuMuon where MaPM='" & MaPhieu & "'").Rows.Count = 0)
    End Function
    Public Shared Function ThemPM(ByVal MaPM As String, ByVal MaDG As String, ByVal MaNV As String, ByVal NgayLap As Date, ByVal GhiChu As String)
        Return db.Query("Insert into PhieuMuon (MaPM,MaDG,MaNV,GhiChu,NgayLap) values('" & MaPM & "','" & MaDG & "','" & MaNV & "',N'" & GhiChu & "','" & NgayLap.ToString("MM/dd/yyyy") & "')")
    End Function
    Public Shared Function CTPM_Muon(ByVal MaPM As String, ByVal IDSach As String, ByVal NgayHenTra As Date)
        Return db.Query("insert into PhieuMuonChiTiet(MaPM,IDSach,NgayHenTra) values('" & MaPM & "','" & IDSach & "','" & NgayHenTra.ToString("MM/dd/yyyy") & "')")
    End Function
    Public Shared Function CTPM(ByVal MaPM As String)
        Return db.QueryTable("select pmct.IDSach,TenSach,NgayHenTra,NgayTra from PhieuMuonChiTiet pmct inner join Sub_Sach ss on ss.IDSach=pmct.IDSach inner join Sach s on s.MaSach=ss.MaSach where MaPM='" & MaPM & "' and pmct.NgayTra is NULL")
    End Function
    Public Shared Function ThongTinPM(ByVal MaPM As String)
        Return db.QueryTable("select pm.MaDG,TenDG,GhiChu,NgayLap from PhieuMuon pm inner join TheDocGia t on t.MaDG=pm.MaDG where MaPM='" & MaPM & "'")
    End Function
    Public Shared Function TraSach(ByVal MaPM As String, ByVal IDSach As String, ByVal NgayTra As Date)
        Return db.Query("UPDATE PhieuMuonChiTiet set NgayTra='" & NgayTra.ToString("MM/dd/yyyy") & "'where MaPM='" & MaPM & "' and IDSach='" & IDSach & "'")
    End Function
    Public Shared Function PhieuMuonTrongThang(ByVal Thang As Integer) As DataTable
        Return db.QueryTable("select MaPM,TenDG,TenNV,NgayLap,GhiChu from PhieuMuon pm inner join TheDocGia dg on dg.MaDG=pm.MaDG inner join NhanVien nv on nv.MaNV=pm.MaNV where month(NgayLap)=" & Thang)
    End Function
End Class
